﻿using System;
using System.Globalization;

namespace TrackIT.Common.Providers
{
    public class DateTimeProvider : IDateTimeProvider
    {
        private static readonly GregorianCalendar _gregorianCalendar = new GregorianCalendar();

        public DateTime Now
        {
            get { return DateTime.Now; }
        }

        public int GetWeekNumberOfMonth(DateTime date)
        {
            DateTime first = new DateTime(date.Year, date.Month, 1);
            return GetWeekOfYear(date) - GetWeekOfYear(first) + 1;
        }

        public int GetWeekOfYear(DateTime time)
        {
            return _gregorianCalendar.GetWeekOfYear(time, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
        }
    }
}